<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .box {
      width: 100px;
      height: 100px;
      border: dashed 2px #ccc;
      position: relative;
    }
  
    input[type="file"] {
      position: absolute;
      left: 0;
      top: 0;
      opacity: 0;
      width: 100px;
      height: 100px;
      z-index: 1;
    }
</style>
<body>
    <div class="container"></div>
    <button>+</button>

    <script src="http://unpkg.com/jquery"></script>
    <script>
    $("button").click(function () {
        // 给container加一个盒模型
        $(".container").append(`
        <div class="box">
            <input type="file" />
        </div>
        `);
        // 触发这个盒模型点击事件
        $(".box:last").trigger("click");
    });

    $(".container").on("change", ".box", function () {
        // console.log(this.files[0]);
        const reader = new FileReader();
        reader.readAsDataURL($(this).find("input")[0].files[0]);
        reader.onload = (e) => {
        // console.log(e.target.result);
        $(this).css({
            backgroundImage: `url(${e.target.result})`,
            backgroundSize: "100% 100%",
        });
        };
    });
    </script>
</body>
</html>